﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCamera;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using COC.GameLogic;

namespace COC
{
	static class CameraUpdater
	{
		public static void BindCameraToActor(Camera camera, AnimActor actor)
		{
			Vector3 bbUp = new Vector3(
				(actor.BoundingBox.Max.X + actor.BoundingBox.Min.X) * 0.5f,
				(actor.BoundingBox.Max.Y),
				(actor.BoundingBox.Max.Z + actor.BoundingBox.Min.Z) * 0.5f);
			bbUp = Vector3.Transform(bbUp, actor.LocalToWorldMat);
			Vector3 actorDir = Vector3.TransformNormal(new Vector3(0, 0, 1), actor.LocalToWorldMat);
			camera.SetPosition(bbUp - actorDir * 5.0f);
			camera.SetDirection(actorDir);
		}

		public static void UpdateCamera(Camera camera, AnimActor actor, Vector2 mouseMove)
		{
			Vector3 bbUp = new Vector3(
				(actor.BoundingBox.Max.X + actor.BoundingBox.Min.X) * 0.5f,
				(actor.BoundingBox.Max.Y),
				(actor.BoundingBox.Max.Z + actor.BoundingBox.Min.Z) * 0.5f);
			bbUp = Vector3.Transform(bbUp, actor.LocalToWorldMat);
			camera.RotateAxisAngleCenter(new Vector3(0, 1, 0), mouseMove.X, bbUp);
			camera.RotateAxisAngleCenter(camera.Right, mouseMove.Y, bbUp);
		}
	}
}